
#include <controls/menu/cxisidebarmenu.h>
#include <private/menu/cxisidebarmenu/cxisidebarmenu_p.h>
CxiSideBarMenu::CxiSideBarMenu(QWidget* parent)
	: QWidget(parent), d_ptr(new CxiSideBarMenuPrivate(this))
{
}

CxiSideBarMenu::~CxiSideBarMenu()
{
}

QTreeWidgetItem* CxiSideBarMenu::addMenu(const QString& title)
{
	Q_D(CxiSideBarMenu);
	auto* menuItem = new QTreeWidgetItem;
	menuItem->setText(0, title);
	d->m_treeWidget->addTopLevelItem(menuItem);
	return menuItem;
}

void CxiSideBarMenu::buildMenu(const QList<QTreeWidgetItem*>& items)
{
	Q_D(CxiSideBarMenu);
	d->m_treeWidget->addTopLevelItems(items);
}
void CxiSideBarMenu::addMenu(QTreeWidgetItem* item)
{
	Q_D(CxiSideBarMenu);
	d->m_treeWidget->addTopLevelItem(item);
}
void CxiSideBarMenu::setWidget(QWidget* widget, SideBarCorner corner)
{
	Q_D(CxiSideBarMenu);
	if (corner == Top)
		d->m_mainLayout->insertWidget(0, widget);
	else
		d->m_mainLayout->addWidget(widget);
}
void CxiSideBarMenu::clearMenu()
{
	Q_D(CxiSideBarMenu);
	d->m_treeWidget->clear();
}
void CxiSideBarMenu::onItemTriggered(QTreeWidgetItem* item)
{
	emit itemTriggerd(item);
}